/*++

Copyright (c) 1990-2011 Microsoft Corporation.  All Rights Reserved

Module Name:
    common.h

Abstract: 

Author:

Enviroment:

Revision History:

--*/


#ifndef _COMMON_H_
#define _COMMON_H_

#include <ntddk.h>

#define DISK_DEVICE         0x00

#define UNIT_MS(x)			((x)*(-1)*(10)*1000)
#define UNIT_SEC(x)			(UNIT_MS(x)*1000)

#define CMDC_REQUEST_NOP        (0x00)
#define CMDC_REQUEST_LOGIN      (0x03)
#define CMDC_REQUEST_COMMAND    (0x01)

#define CMDC_RESPONS_NOP        (0x20)
#define CMDC_RESPONS_LOGIN      (0x23)
#define CMDC_RESPONS_COMMAND    (0x25)
#define CMDC_RESPONS_REPORT     (0x21)

#define SCSI_READ10             (0x28)

#define LinkedPos					(3)
#define Linked						(1<<LinkedPos)
#define GetLinked(x)				(((x)&Linked)>>LinkedPos)
#define RelAddrPos					(7)
#define RelAddr						(1<<RelAddrPos)
#define GetRelAddr(x)				(((x)&RelAddr)>>RelAddrPos)
#define SyncPos						(4)
#define Sync						(1<<SyncPos)
#define GetSync(x)					(((x)&Sync)>>SyncPos)
#define WBus32Pos					(6)
#define WBus32						(1<<WBus32Pos)
#define GetWBus32(x)				(((x)&WBus32)>>WBus32Pos)
#define WBus16Pos					(5)
#define WBus16						(1<<WBus16Pos)
#define GetWBus16(x)				(((x)&WBus16)>>WBus16Pos)
#define ResponseDataPos				(0)
#define ResponseData(x)				(((x)&0x0000000F)<<ResponseDataPos)
#define GetResponseData(x)			(((x)&ResponseData(0xffffffff))>>ResponseDataPos)

typedef struct _INQUIRY_ANSWER_T {
    UCHAR 	PeripheralParameters;
    UCHAR 	DeviceType;
    UCHAR 	StandartCapabilities;
    UCHAR 	ResponseFormat;
    UCHAR 	AdditionalLength;
    UCHAR 	Reserved[2];
    UCHAR 	DeviceParameters;
    UCHAR	VendorId[8];
    UCHAR	ProductId[16];
    UCHAR	ProductRevision[4];
} INQUIRY_ANSWER_T, *PINQUIRY_ANSWER_T ;


typedef struct _MP_DEVICE_INFO {
    UCHAR    DeviceType;
    UCHAR    TargetID;
    UCHAR    LunID;
} MP_DEVICE_INFO, *pMP_DEVICE_INFO;

typedef struct _MP_DEVICE_LIST {
    ULONG          DeviceCount;
    MP_DEVICE_INFO DeviceInfo[1];
} MP_DEVICE_LIST, *pMP_DEVICE_LIST;

typedef enum _STATUS_MESS_ {
    ST_FALSE,
    ST_TRUE
};

typedef struct _PDU_COUNTER_{
    unsigned short CommandCounter;
    unsigned short NopCounter;
    unsigned short LoginCounter;
}PDU_COUNTER, *PPDU_COUNTER;

typedef struct _HEAD_PDU_ {
    unsigned char CMDC;
    unsigned char Flags;
    unsigned short DSL;
    unsigned short ITT;
    unsigned short CmdSN;
} HEAD_PDU, *PHEAD_PDU;

typedef struct _LOGIN_PDU_ {
    HEAD_PDU head;
    unsigned int InitiatorName;
    unsigned int TargetName;
    unsigned int ConnectionParameterAddress;
    unsigned int ConnectionParameterValue;
    unsigned int Reserved;
    unsigned int HeaderCRC;
} LOGIN_PDU, *PLOGIN_PDU;

typedef struct _TERMINATE_PDU_ {
    HEAD_PDU head;
    unsigned int Reserved[5];
    unsigned int HeaderCRC;
} TERMINATE_PDU, *PTERMINATE_PDU;

typedef struct _NOP_PDU_ {
    HEAD_PDU head;
    unsigned int Reserved[5];
    unsigned int HeaderCRC;
} NOP_PDU, *PNOP_PDU;

typedef struct _CDB_ {
    unsigned char CDB_CMD;
    unsigned char Reserved0;
    unsigned int  Lba;
    unsigned char Reserved1;
    unsigned short Length;
    unsigned char Reserved2;
} CDB_, *PCDB_;

typedef struct _COMMAND_PDU_ {
    HEAD_PDU head;
    unsigned int ExpectedDataTransferLength;
    union {
        unsigned char ucCDB[16];
        unsigned int uiCDB[4];
        CDB_ cdb;
    } U;
    unsigned int HeaderCRC;
} COMMAND_PDU, *PCOMMAND_PDU;

typedef union _PDU_ {
    LOGIN_PDU       LoginPDU;
    TERMINATE_PDU   TerminatePDU;
    COMMAND_PDU     CommandPDU;
} PDU, *PPDU;

typedef union _INDIAN_ {
    unsigned short d;
    unsigned char b[2];
} IND, *PIND;

#endif    // _COMMON_H_
